package com.chixing.controller;

import com.chixing.commons.ServerResponse;
import com.chixing.commons.TokenUtil;
import com.chixing.pojo.JobDetail;
import com.chixing.pojo.LoginPerson;
import com.chixing.pojo.PersonCenter;
import com.chixing.service.IPersonCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
public class PersonalCenterController {
    @Autowired
    public IPersonCenterService personCenterService;


    @GetMapping("/getById/{id}")
    @ResponseBody
    public ServerResponse getById(@PathVariable("id") Integer perId){
        return personCenterService.getByPersonal(perId);
    }


    @PostMapping("getByPersonal")
    public ServerResponse getByPersonal(String token){
        LoginPerson tokens=TokenUtil.parseToken(token); //将存储的token数据转换放入loginPerson
        System.out.println("tokens："+tokens);
        if (tokens !=null){
            ServerResponse byPersonal = personCenterService.getByPersonal(tokens.getPersonId());//将token数据全部查出来
            System.out.println(byPersonal);
            return byPersonal;
        }
        return null;
    }

    @PostMapping("updatePerson")
    public ServerResponse updatePerson(String token,PersonCenter personCenter,HttpServletRequest request){
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++"+personCenter);

        ServerResponse serverResponse =personCenterService.update(personCenter,token);
        return serverResponse;
    }

}
